package ev.ftw.app;

import com.affymetrix.genoviz.awt.AdjustableJSlider;
import com.affymetrix.genoviz.widget.NeoMap;
import com.affymetrix.genoviz.glyph.BasicGraphGlyph;

import ev.ftw.dna.DNA_Schizosaccharomyces_pombe;
import ev.ftw.dna.Cromosoma;
import ev.ftw.dna.HiloExp;

import java.awt.Adjustable;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.border.TitledBorder;
import javax.swing.DefaultComboBoxModel;
import java.util.ResourceBundle;

public class AplicacionFTW extends JFrame {
	private static final ResourceBundle languageBundle = ResourceBundle.getBundle("ev.ftw.app.spanish"); //$NON-NLS-1$
	private static final long serialVersionUID = 1L;
	NeoMap map;
	AdjustableJSlider xzoomer;
	AdjustableJSlider yzoomer;
	//Vector selected = new Vector();
	
	DNA_Schizosaccharomyces_pombe adnTrabajo;
	
	private JPanel contentPane;
	JComboBox cbxCromosoma;
	JLabel lblStatus;

	int off = 0;
	private JTextField txtBandwith;
	private JTextField txtLimiteFiltroWLT;
	private JTextField txtEliminaErrores;
	private JTextField txtAmpliaResolucion;
	private JTextField txtReducirResolucion;
	private JLabel lblResolucionActual;
	private JTextField txtFicheroOperaciones;
	private JTextField txtUmbralExpresionMedia;
	private JTextField txtUmbralExpresionWLT;
	private JTextField txtUmbralSaltoWLT;
	private JComboBox cbxOperaADN;
	private JTextField txtOperarNumero;
	private JComboBox cbxOperarNumero;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AplicacionFTW frame = new AplicacionFTW();
					frame.setVisible(true);
					frame.setResizable(false);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public void pintarCromosoma(Cromosoma c){
		Cromosoma aux = c.clone();
		
		aux.aumentaResolucion(c.getResolucion());
		map.clearWidget();
		map.addAxis(0);
		double xcoords[] = new double[aux.getCompleto().length-1];
		double ycoords[] = new double[aux.getCompleto().length-1];
		for(int i = 0; i < xcoords.length; i++){
			xcoords[i] = i+1;
			ycoords[i] = aux.getCompleto()[i+1]*10;
		}

		map.setMapRange(0, aux.getCompleto().length);
		map.configure("-glyphtype BasicGraphGlyph -foreground pink -offset 0 "
				+ "-width 120 -packer null");
		BasicGraphGlyph sg = (BasicGraphGlyph) map.addItem(0, aux.getCompleto().length);
		sg.setPointCoords(xcoords, ycoords);
		sg.setBackgroundColor(Color.red);
		
		xcoords = null;
		ycoords = null;
		aux = null;
		
		float media = c.media();
		float mediaSup = c.mediaSup(media);
		float mediaInf = c.mediaInf(media);
		float sugerenciaMedia = mediaSup - ((mediaSup-media)/2);
		float sugerenciaSaltoFiltro = mediaSup - mediaInf;
		float sugerenciaSaltoWLT = (mediaSup - mediaInf) - ((media - mediaInf)/4);
		
		txtLimiteFiltroWLT.setText("" + sugerenciaSaltoFiltro);
		txtUmbralExpresionMedia.setText("" + sugerenciaMedia);
		txtUmbralExpresionWLT.setText("" + sugerenciaMedia);
		txtUmbralSaltoWLT.setText("" + sugerenciaSaltoWLT);
		
		map.updateWidget();
		lblResolucionActual.setText("Actual: " + c.getResolucion() + ":1");
		System.gc();
	}
	
	/**
	 * Create the frame.
	 */
	public AplicacionFTW() {
		setTitle(languageBundle.getString("AplicacionFTW.this.title")); //$NON-NLS-1$
		
		map = new NeoMap(true, true);  // no internal vertical scroller
		map.setMapOffset(-250, 150);
		//map.setMinZoom(NeoMap.Y, 10);
		map.addAxis(0);
		
		xzoomer = new AdjustableJSlider(Adjustable.HORIZONTAL);
		yzoomer = new AdjustableJSlider(Adjustable.VERTICAL);
		map.setZoomer(NeoMap.X, xzoomer);
		map.setZoomer(NeoMap.Y, yzoomer);
		
//		map.addComponentListener(this);
		
		
		
		/*double xcoords[] = {0, 100, 200, 300, 400, 500, 600, 700, 800, 900};
		double ycoords[] = {0, -50, -25, 25, 100, 50, 175, -10, 50, 74};*/
		/*Cromosoma c = new Cromosoma();
		c.leerFicheroExpresion("Me0h.wig");
		c.rellenaCompletoSondas();
		//c.reduceResolucion(100);
		double xcoords[] = new double[c.getCompleto().length-1];
		double ycoords[] = new double[c.getCompleto().length-1];
		for(int i = 0; i < xcoords.length; i++){
			xcoords[i] = i+1;
			ycoords[i] = c.getCompleto()[i+1]*10;
		}

		map.setMapRange(0, c.getCompleto().length);
		map.configure("-glyphtype BasicGraphGlyph -foreground pink -offset 0 "
				+ "-width 120 -packer null");
		BasicGraphGlyph sg = (BasicGraphGlyph) map.addItem(0, c.getCompleto().length);
		sg.setPointCoords(xcoords, ycoords);
		sg.setBackgroundColor(Color.red);*/
		map.setMapRange(0, 1000000);
		
		
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1071, 780);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 59, 886, 300);
		contentPane.add(panel);
		
		panel.setLayout(new BorderLayout());
		panel.add("Center", map);
		panel.add("North", xzoomer);
		panel.add("West", yzoomer);
		
		JMenuBar menuBar = new JMenuBar();
		menuBar.setBounds(0, 0, 1055, 21);
		contentPane.add(menuBar);
		
		JMenu mnNewMenu = new JMenu(languageBundle.getString("AplicacionFTW.mnNewMenu.text")); //$NON-NLS-1$
		menuBar.add(mnNewMenu);
		
		JMenuItem mnCargarWig = new JMenuItem(languageBundle.getString("AplicacionFTW.mnCargarWig.text")); //$NON-NLS-1$
		mnCargarWig.addActionListener(new OpenL());
		mnNewMenu.add(mnCargarWig);
		
		JMenuItem mnSalvarWig = new JMenuItem(languageBundle.getString("AplicacionFTW.mnSalvarWig.text")); //$NON-NLS-1$
		mnSalvarWig.addActionListener(new SaveL());
		mnNewMenu.add(mnSalvarWig);
		
		JMenuItem mnSalir = new JMenuItem(languageBundle.getString("AplicacionFTW.mnSalir.text")); //$NON-NLS-1$
		mnNewMenu.add(mnSalir);
		
		/*JMenu mnIdioma = new JMenu(languageBundle.getString("AplicacionFTW.mnIdioma.text")); //$NON-NLS-1$
		menuBar.add(mnIdioma);
		
		JMenuItem mntmCastellano = new JMenuItem(languageBundle.getString("AplicacionFTW.mntmCastellano.text")); //$NON-NLS-1$
		mnIdioma.add(mntmCastellano);
		
		JMenuItem mntmIngls = new JMenuItem(languageBundle.getString("AplicacionFTW.mntmIngls.text")); //$NON-NLS-1$
		mnIdioma.add(mntmIngls);*/
		
		JMenu mnAyuda = new JMenu(languageBundle.getString("AplicacionFTW.mnAyuda.text")); //$NON-NLS-1$
		menuBar.add(mnAyuda);
		
		JMenuItem mntmAcercaDe = new JMenuItem(languageBundle.getString("AplicacionFTW.mntmAcercaDe.text")); //$NON-NLS-1$
		mntmAcercaDe.addActionListener(new MuestraDialogo());
		mnAyuda.add(mntmAcercaDe);
		
		cbxCromosoma = new JComboBox();
		cbxCromosoma.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent arg0) {
				if(arg0.getStateChange() == ItemEvent.SELECTED){
					pintarCromosoma(adnTrabajo.getCromosomas()[cbxCromosoma.getSelectedIndex()]);
				}
			}
		});
		cbxCromosoma.setBounds(906, 81, 144, 20);
		contentPane.add(cbxCromosoma);
		
		lblStatus = new JLabel(""); //$NON-NLS-1$
		lblStatus.setFont(new Font("Times New Roman", Font.BOLD, 13));
		lblStatus.setBounds(10, 28, 886, 20);
		contentPane.add(lblStatus);
		
		JLabel lblCromosomaAVisualizar = new JLabel(languageBundle.getString("AplicacionFTW.lblCromosomaAVisualizar.text")); //$NON-NLS-1$
		lblCromosomaAVisualizar.setBounds(906, 59, 144, 14);
		contentPane.add(lblCromosomaAVisualizar);
		
		JPanel panelFiltros = new JPanel();
		panelFiltros.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null)); //$NON-NLS-1$
		panelFiltros.setBounds(10, 370, 342, 203);
		contentPane.add(panelFiltros);
		panelFiltros.setLayout(null);
		
		JLabel lblFiltros = new JLabel(languageBundle.getString("AplicacionFTW.lblFiltros.text")); //$NON-NLS-1$
		lblFiltros.setBounds(147, 0, 46, 14);
		panelFiltros.add(lblFiltros);
		
		JLabel lblFiltroAnchoDe = new JLabel(languageBundle.getString("AplicacionFTW.lblFiltroAnchoDe.text")); //$NON-NLS-1$
		lblFiltroAnchoDe.setBounds(10, 24, 282, 14);
		panelFiltros.add(lblFiltroAnchoDe);
		
		txtBandwith = new JTextField();
		txtBandwith.setText(languageBundle.getString("AplicacionFTW.txtBandwith.text")); //$NON-NLS-1$
		txtBandwith.setBounds(147, 38, 86, 20);
		panelFiltros.add(txtBandwith);
		txtBandwith.setColumns(10);
		
		JLabel lblTamannoBandwith = new JLabel(languageBundle.getString("AplicacionFTW.lblTamannoBandwith.text")); //$NON-NLS-1$
		lblTamannoBandwith.setBounds(10, 41, 46, 14);
		panelFiltros.add(lblTamannoBandwith);
		
		JButton btnAplicar = new JButton(languageBundle.getString("AplicacionFTW.btnAplicar.text")); //$NON-NLS-1$
		btnAplicar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				if(adnTrabajo == null) return;
				
				lblStatus.setText("Aplicando");
		    	lblStatus.update(lblStatus.getGraphics());
				
				adnTrabajo.bandwith(Integer.parseInt(txtBandwith.getText()));
				pintarCromosoma(adnTrabajo.getCromosomas()[cbxCromosoma.getSelectedIndex()]);
				
				lblStatus.setText("Listo");
		    	lblStatus.update(lblStatus.getGraphics());
			}
		});
		btnAplicar.setBounds(243, 37, 89, 23);
		panelFiltros.add(btnAplicar);
		
		JLabel lblFiltroWavelet = new JLabel(languageBundle.getString("AplicacionFTW.lblFiltroWavelet.text")); //$NON-NLS-1$
		lblFiltroWavelet.setBounds(10, 77, 282, 14);
		panelFiltros.add(lblFiltroWavelet);
		
		JLabel lblLmiteDeSalto = new JLabel(languageBundle.getString("AplicacionFTW.lblLmiteDeSalto.text")); //$NON-NLS-1$
		lblLmiteDeSalto.setBounds(10, 102, 103, 14);
		panelFiltros.add(lblLmiteDeSalto);
		
		txtLimiteFiltroWLT = new JTextField();
		txtLimiteFiltroWLT.setText(languageBundle.getString("AplicacionFTW.txtLimiteFiltroWLT.text")); //$NON-NLS-1$
		txtLimiteFiltroWLT.setBounds(147, 99, 86, 20);
		panelFiltros.add(txtLimiteFiltroWLT);
		txtLimiteFiltroWLT.setColumns(10);
		
		JButton cmdAplicarFiltroWLT = new JButton(languageBundle.getString("AplicacionFTW.cmdAplicarFiltroWLT.text")); //$NON-NLS-1$
		cmdAplicarFiltroWLT.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				if(adnTrabajo == null) return;
				
				lblStatus.setText("Aplicando");
		    	lblStatus.update(lblStatus.getGraphics());
				
				adnTrabajo.filtroWLT(Float.parseFloat(txtBandwith.getText()));
				pintarCromosoma(adnTrabajo.getCromosomas()[cbxCromosoma.getSelectedIndex()]);
				
				lblStatus.setText("Listo");
		    	lblStatus.update(lblStatus.getGraphics());
			}
		});
		cmdAplicarFiltroWLT.setBounds(243, 98, 89, 23);
		panelFiltros.add(cmdAplicarFiltroWLT);
		
		JLabel lblEliminaErrores = new JLabel(languageBundle.getString("AplicacionFTW.lblEliminaErrores.text")); //$NON-NLS-1$
		lblEliminaErrores.setBounds(10, 138, 162, 14);
		panelFiltros.add(lblEliminaErrores);
		
		JLabel lblAnchoDeLa = new JLabel(languageBundle.getString("AplicacionFTW.lblAnchoDeLa.text")); //$NON-NLS-1$
		lblAnchoDeLa.setBounds(10, 163, 127, 14);
		panelFiltros.add(lblAnchoDeLa);
		
		txtEliminaErrores = new JTextField();
		txtEliminaErrores.setText(languageBundle.getString("AplicacionFTW.txtEliminaErrores.text")); //$NON-NLS-1$
		txtEliminaErrores.setBounds(147, 160, 86, 20);
		panelFiltros.add(txtEliminaErrores);
		txtEliminaErrores.setColumns(10);
		
		JButton cmdAplicarEliminaErrores = new JButton(languageBundle.getString("AplicacionFTW.cmdAplicarEliminaErrores.text")); //$NON-NLS-1$
		cmdAplicarEliminaErrores.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(adnTrabajo == null) return;
				
				lblStatus.setText("Aplicando");
		    	lblStatus.update(lblStatus.getGraphics());
				
				adnTrabajo.eliminaErrores(Integer.parseInt(txtEliminaErrores.getText()));
				pintarCromosoma(adnTrabajo.getCromosomas()[cbxCromosoma.getSelectedIndex()]);
				
				lblStatus.setText("Listo");
		    	lblStatus.update(lblStatus.getGraphics());
			}
		});
		cmdAplicarEliminaErrores.setBounds(243, 159, 89, 23);
		panelFiltros.add(cmdAplicarEliminaErrores);
		
		JPanel panelResolucion = new JPanel();
		panelResolucion.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null)); //$NON-NLS-1$
		panelResolucion.setBounds(10, 584, 342, 147);
		contentPane.add(panelResolucion);
		panelResolucion.setLayout(null);
		
		JLabel lblResolucion = new JLabel(languageBundle.getString("AplicacionFTW.lblResolucion.text")); //$NON-NLS-1$
		lblResolucion.setBounds(139, 0, 91, 14);
		panelResolucion.add(lblResolucion);
		
		JLabel lblAmpliaResolucion = new JLabel(languageBundle.getString("AplicacionFTW.lblAmpliaResolucion.text")); //$NON-NLS-1$
		lblAmpliaResolucion.setBounds(10, 50, 160, 14);
		panelResolucion.add(lblAmpliaResolucion);
		
		JLabel lblUnidades = new JLabel(languageBundle.getString("AplicacionFTW.lblUnidades.text")); //$NON-NLS-1$
		lblUnidades.setBounds(10, 67, 76, 14);
		panelResolucion.add(lblUnidades);
		
		txtAmpliaResolucion = new JTextField();
		txtAmpliaResolucion.setText(languageBundle.getString("AplicacionFTW.txtAmpliaResolucion.text")); //$NON-NLS-1$
		txtAmpliaResolucion.setBounds(144, 64, 86, 20);
		panelResolucion.add(txtAmpliaResolucion);
		txtAmpliaResolucion.setColumns(10);
		
		JButton cmdAmpliaResolucion = new JButton(languageBundle.getString("AplicacionFTW.cmdAmpliaResolucion.text")); //$NON-NLS-1$
		cmdAmpliaResolucion.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(adnTrabajo == null) return;
				
				lblStatus.setText("Aplicando");
		    	lblStatus.update(lblStatus.getGraphics());
				
				adnTrabajo.ampliarResolucion(Integer.parseInt(txtAmpliaResolucion.getText()));
				pintarCromosoma(adnTrabajo.getCromosomas()[cbxCromosoma.getSelectedIndex()]);
				
				lblStatus.setText("Listo");
		    	lblStatus.update(lblStatus.getGraphics());
			}
		});
		cmdAmpliaResolucion.setBounds(243, 63, 89, 23);
		panelResolucion.add(cmdAmpliaResolucion);
		
		JLabel lblReducirResolucin = new JLabel(languageBundle.getString("AplicacionFTW.lblReducirResolucin.text")); //$NON-NLS-1$
		lblReducirResolucin.setBounds(10, 102, 160, 14);
		panelResolucion.add(lblReducirResolucin);
		
		JLabel lblUnidades_1 = new JLabel(languageBundle.getString("AplicacionFTW.lblUnidades_1.text")); //$NON-NLS-1$
		lblUnidades_1.setBounds(10, 117, 113, 14);
		panelResolucion.add(lblUnidades_1);
		
		txtReducirResolucion = new JTextField();
		txtReducirResolucion.setText(languageBundle.getString("AplicacionFTW.txtReducirResolucion.text")); //$NON-NLS-1$
		txtReducirResolucion.setBounds(144, 114, 86, 20);
		panelResolucion.add(txtReducirResolucion);
		txtReducirResolucion.setColumns(10);
		
		JButton cmdReducirResolucion = new JButton(languageBundle.getString("AplicacionFTW.cmdReducirResolucion.text")); //$NON-NLS-1$
		cmdReducirResolucion.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(adnTrabajo == null) return;
				
				lblStatus.setText("Aplicando");
		    	lblStatus.update(lblStatus.getGraphics());
				
				adnTrabajo.reducirResolucion(Integer.parseInt(txtReducirResolucion.getText()));
				pintarCromosoma(adnTrabajo.getCromosomas()[cbxCromosoma.getSelectedIndex()]);
				
				lblStatus.setText("Listo");
		    	lblStatus.update(lblStatus.getGraphics());
			}
		});
		cmdReducirResolucion.setBounds(243, 113, 89, 23);
		panelResolucion.add(cmdReducirResolucion);
		
		lblResolucionActual = new JLabel(languageBundle.getString("AplicacionFTW.lblResolucionActual.text")); //$NON-NLS-1$
		lblResolucionActual.setBounds(10, 23, 239, 14);
		panelResolucion.add(lblResolucionActual);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null)); //$NON-NLS-1$
		panel_1.setBounds(362, 370, 390, 203);
		contentPane.add(panel_1);
		panel_1.setLayout(null);
		
		JLabel lblGenerarGff = new JLabel(languageBundle.getString("AplicacionFTW.lblGenerarGff.text")); //$NON-NLS-1$
		lblGenerarGff.setBounds(144, 0, 115, 14);
		panel_1.add(lblGenerarGff);
		
		JLabel lblATravsDe = new JLabel(languageBundle.getString("AplicacionFTW.lblATravsDe.text")); //$NON-NLS-1$
		lblATravsDe.setBounds(10, 35, 164, 14);
		panel_1.add(lblATravsDe);
		
		JLabel lblUmbralDeExpresin = new JLabel(languageBundle.getString("AplicacionFTW.lblUmbralDeExpresin.text")); //$NON-NLS-1$
		lblUmbralDeExpresin.setBounds(10, 60, 147, 14);
		panel_1.add(lblUmbralDeExpresin);
		
		txtUmbralExpresionMedia = new JTextField();
		txtUmbralExpresionMedia.setText(languageBundle.getString("AplicacionFTW.txtUmbralExpresionMedia.text")); //$NON-NLS-1$
		txtUmbralExpresionMedia.setBounds(140, 57, 115, 20);
		panel_1.add(txtUmbralExpresionMedia);
		txtUmbralExpresionMedia.setColumns(10);
		
		JButton btnGenerar = new JButton(languageBundle.getString("AplicacionFTW.btnGenerar.text")); //$NON-NLS-1$
		btnGenerar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(adnTrabajo == null) return;
				JFileChooser c = new JFileChooser();
			      c.setFileFilter(new GffFileFilter());
			      // Demonstrate "Open" dialog:
			      int rVal = c.showSaveDialog(AplicacionFTW.this);
			      if (rVal == JFileChooser.APPROVE_OPTION) {
			    	  
			    	  lblStatus.setText("Generando: " + c.getSelectedFile().toString());
				      lblStatus.update(lblStatus.getGraphics());
			    	  
			    	  adnTrabajo.expresionSencilla(Float.parseFloat(txtUmbralExpresionMedia.getText()), c.getSelectedFile().toString());
			    	  
			    	  lblStatus.setText("Listo");
				      lblStatus.update(lblStatus.getGraphics());
			      }
			      if (rVal == JFileChooser.CANCEL_OPTION) {

			      }
			}
		});
		btnGenerar.setBounds(265, 56, 115, 23);
		panel_1.add(btnGenerar);
		
		JLabel lblMedianteWavelets = new JLabel(languageBundle.getString("AplicacionFTW.lblMedianteWavelets.text")); //$NON-NLS-1$
		lblMedianteWavelets.setBounds(10, 114, 147, 14);
		panel_1.add(lblMedianteWavelets);
		
		JLabel lblUmbralDeExpresin_1 = new JLabel(languageBundle.getString("AplicacionFTW.lblUmbralDeExpresin_1.text")); //$NON-NLS-1$
		lblUmbralDeExpresin_1.setBounds(10, 139, 123, 14);
		panel_1.add(lblUmbralDeExpresin_1);
		
		JLabel lblUmbralDeSalto = new JLabel(languageBundle.getString("AplicacionFTW.lblUmbralDeSalto.text")); //$NON-NLS-1$
		lblUmbralDeSalto.setBounds(10, 164, 123, 14);
		panel_1.add(lblUmbralDeSalto);
		
		txtUmbralExpresionWLT = new JTextField();
		txtUmbralExpresionWLT.setText(languageBundle.getString("AplicacionFTW.txtUmbralExpresionWLT.text")); //$NON-NLS-1$
		txtUmbralExpresionWLT.setBounds(140, 136, 119, 20);
		panel_1.add(txtUmbralExpresionWLT);
		txtUmbralExpresionWLT.setColumns(10);
		
		txtUmbralSaltoWLT = new JTextField();
		txtUmbralSaltoWLT.setText(languageBundle.getString("AplicacionFTW.txtUmbralSaltoWLT.text")); //$NON-NLS-1$
		txtUmbralSaltoWLT.setBounds(140, 164, 119, 20);
		panel_1.add(txtUmbralSaltoWLT);
		txtUmbralSaltoWLT.setColumns(10);
		
		JButton cmdGenerarWLT = new JButton(languageBundle.getString("AplicacionFTW.cmdGenerarWLT.text")); //$NON-NLS-1$
		cmdGenerarWLT.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(adnTrabajo == null) return;
				JFileChooser c = new JFileChooser();
			      c.setFileFilter(new GffFileFilter());
			      // Demonstrate "Open" dialog:
			      int rVal = c.showSaveDialog(AplicacionFTW.this);
			      if (rVal == JFileChooser.APPROVE_OPTION) {
			    	  
			    	  lblStatus.setText("Generando: " + c.getSelectedFile().toString());
				      lblStatus.update(lblStatus.getGraphics());
			    	  
			    	  adnTrabajo.expresionWLT(Float.parseFloat(txtUmbralSaltoWLT.getText()), Float.parseFloat(txtUmbralExpresionWLT.getText()), c.getSelectedFile().toString());
			    	  
			    	  lblStatus.setText("Listo");
				      lblStatus.update(lblStatus.getGraphics());
			      }
			      if (rVal == JFileChooser.CANCEL_OPTION) {

			      }
			}
		});
		cmdGenerarWLT.setBounds(265, 145, 115, 23);
		panel_1.add(cmdGenerarWLT);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null)); //$NON-NLS-1$
		panel_2.setBounds(362, 584, 390, 147);
		contentPane.add(panel_2);
		panel_2.setLayout(null);
		
		JLabel lblOperaciones = new JLabel(languageBundle.getString("AplicacionFTW.lblOperaciones.text")); //$NON-NLS-1$
		lblOperaciones.setBounds(149, 0, 116, 14);
		panel_2.add(lblOperaciones);
		
		txtFicheroOperaciones = new JTextField();
		txtFicheroOperaciones.setBounds(10, 61, 255, 20);
		panel_2.add(txtFicheroOperaciones);
		txtFicheroOperaciones.setColumns(10);
		
		JLabel lblGenomaParaOperar = new JLabel(languageBundle.getString("AplicacionFTW.lblGenomaParaOperar.text")); //$NON-NLS-1$
		lblGenomaParaOperar.setBounds(10, 36, 273, 14);
		panel_2.add(lblGenomaParaOperar);
		
		JButton cmdOperacionesExaminar = new JButton(languageBundle.getString("AplicacionFTW.cmdOperacionesExaminar.text")); //$NON-NLS-1$
		cmdOperacionesExaminar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JFileChooser c = new JFileChooser();
			      c.setFileFilter(new WigFileFilter());
			      // Demonstrate "Open" dialog:
			      int rVal = c.showOpenDialog(AplicacionFTW.this);
			      if (rVal == JFileChooser.APPROVE_OPTION) {
			        txtFicheroOperaciones.setText(c.getSelectedFile().toString());
			      }
			      if (rVal == JFileChooser.CANCEL_OPTION) {

			      }
			}
		});
		cmdOperacionesExaminar.setBounds(273, 60, 107, 23);
		panel_2.add(cmdOperacionesExaminar);
		
		cbxOperaADN = new JComboBox();
		cbxOperaADN.setModel(new DefaultComboBoxModel(new String[] {"Sumar", "Restar", "Multiplicar", "Dividir"}));
		cbxOperaADN.setBounds(149, 89, 116, 20);
		panel_2.add(cbxOperaADN);
		
		JLabel lblOperacinARealizar = new JLabel(languageBundle.getString("AplicacionFTW.lblOperacinARealizar.text")); //$NON-NLS-1$
		lblOperacinARealizar.setBounds(20, 92, 135, 14);
		panel_2.add(lblOperacinARealizar);
		
		JButton cmdAplicarOperacion = new JButton(languageBundle.getString("AplicacionFTW.cmdAplicarOperacion.text")); //$NON-NLS-1$
		cmdAplicarOperacion.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(adnTrabajo == null)return;
				
				lblStatus.setText("Aplicando");
		    	lblStatus.update(lblStatus.getGraphics());
				
				if(txtFicheroOperaciones.getText().compareTo("") == 0) return;
				DNA_Schizosaccharomyces_pombe operando2 = new DNA_Schizosaccharomyces_pombe(txtFicheroOperaciones.getText());
				switch(cbxOperaADN.getSelectedIndex()){
					case 0:
						adnTrabajo.opera(HiloExp.SUMA, operando2);
						break;
					case 1:
						adnTrabajo.opera(HiloExp.RESTA, operando2);
						break;
					case 2:
						adnTrabajo.opera(HiloExp.MULTIPLICA, operando2);
						break;
					case 3:
						adnTrabajo.opera(HiloExp.DIVIDE, operando2);
						break;
				}
				pintarCromosoma(adnTrabajo.getCromosomas()[cbxCromosoma.getSelectedIndex()]);
				lblStatus.setText("Listo");
		    	lblStatus.update(lblStatus.getGraphics());
			}
		});
		cmdAplicarOperacion.setBounds(273, 113, 107, 23);
		panel_2.add(cmdAplicarOperacion);
		
		JPanel panel_3 = new JPanel();
		panel_3.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null)); //$NON-NLS-1$
		panel_3.setBounds(762, 370, 282, 203);
		contentPane.add(panel_3);
		panel_3.setLayout(null);
		
		JLabel lblGenerarGffAutomticamente = new JLabel(languageBundle.getString("AplicacionFTW.lblGenerarGffAutomticamente.text")); //$NON-NLS-1$
		lblGenerarGffAutomticamente.setBounds(80, 0, 203, 14);
		panel_3.add(lblGenerarGffAutomticamente);
		
		JLabel label_1 = new JLabel(languageBundle.getString("AplicacionFTW.label_1.text")); //$NON-NLS-1$
		label_1.setBounds(10, 49, 164, 14);
		panel_3.add(label_1);
		
		JButton button = new JButton(languageBundle.getString("AplicacionFTW.button.text")); //$NON-NLS-1$
		button.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				JFileChooser c = new JFileChooser();
			      c.setFileFilter(new WigFileFilter());
			      c.setDialogTitle("Elija un fichero WIG como origen");
			      // Demonstrate "Open" dialog:
			      int rVal = c.showOpenDialog(AplicacionFTW.this);
			      if (rVal == JFileChooser.APPROVE_OPTION) {
			    	  
			    	  JFileChooser d = new JFileChooser();
				      d.setFileFilter(new GffFileFilter());
				      d.setDialogTitle("Elija un fichero GFF como destino");
				      // Demonstrate "Open" dialog:
				      rVal = d.showOpenDialog(AplicacionFTW.this);
				      if (rVal == JFileChooser.APPROVE_OPTION) {
				    	  
				    	  lblStatus.setText("Generando: " + d.getSelectedFile().toString());
					      lblStatus.update(lblStatus.getGraphics());
				    	  
					      DNA_Schizosaccharomyces_pombe t = new DNA_Schizosaccharomyces_pombe(c.getSelectedFile().toString());
					      float media = t.getCromosomas()[0].media();
						  float mediaSup = t.getCromosomas()[0].mediaSup(media);
						  float mediaInf = t.getCromosomas()[0].mediaInf(media);
						  float sugerenciaMedia = mediaSup - ((mediaSup-media)/2);
						  float sugerenciaSaltoFiltro = mediaSup - mediaInf;
							
					      t.eliminaErrores(25);
					      t.filtroWLT(sugerenciaSaltoFiltro);
						  t.bandwith(25);
						  t.expresionSencilla(sugerenciaMedia, d.getSelectedFile().toString());
					      				    	  
				    	  lblStatus.setText("Listo");
					      lblStatus.update(lblStatus.getGraphics());
				      }
				      if (rVal == JFileChooser.CANCEL_OPTION) {

				      }
			      }
			      if (rVal == JFileChooser.CANCEL_OPTION) {

			      }
			}
		});
		button.setBounds(126, 74, 107, 23);
		panel_3.add(button);
		
		JLabel label_3 = new JLabel(languageBundle.getString("AplicacionFTW.label_3.text")); //$NON-NLS-1$
		label_3.setBounds(10, 117, 147, 14);
		panel_3.add(label_3);
		
		JButton button_1 = new JButton(languageBundle.getString("AplicacionFTW.button_1.text")); //$NON-NLS-1$
		button_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				JFileChooser c = new JFileChooser();
			      c.setFileFilter(new WigFileFilter());
			      c.setDialogTitle("Elija un fichero WIG como origen");
			      // Demonstrate "Open" dialog:
			      int rVal = c.showOpenDialog(AplicacionFTW.this);
			      if (rVal == JFileChooser.APPROVE_OPTION) {
			    	  
			    	  JFileChooser d = new JFileChooser();
				      d.setFileFilter(new GffFileFilter());
				      d.setDialogTitle("Elija un fichero GFF como destino");
				      // Demonstrate "Open" dialog:
				      rVal = d.showOpenDialog(AplicacionFTW.this);
				      if (rVal == JFileChooser.APPROVE_OPTION) {
				    	  
				    	  lblStatus.setText("Generando: " + d.getSelectedFile().toString());
					      lblStatus.update(lblStatus.getGraphics());
				    	  
					      DNA_Schizosaccharomyces_pombe t = new DNA_Schizosaccharomyces_pombe(c.getSelectedFile().toString());
					      float media = t.getCromosomas()[0].media();
						  float mediaSup = t.getCromosomas()[0].mediaSup(media);
						  float mediaInf = t.getCromosomas()[0].mediaInf(media);
						  float sugerenciaMedia = mediaSup - ((mediaSup-media)/2);
						  float sugerenciaSaltoFiltro = mediaSup - mediaInf;
						  float sugerenciaSaltoWLT = (mediaSup - mediaInf) - ((media - mediaInf)/4);
							
					      t.eliminaErrores(25);
					      t.filtroWLT(sugerenciaSaltoFiltro);
						  t.bandwith(25);
						  t.expresionWLT(sugerenciaSaltoWLT, sugerenciaMedia, d.getSelectedFile().toString());
					      				    	  
				    	  lblStatus.setText("Listo");
					      lblStatus.update(lblStatus.getGraphics());
				      }
				      if (rVal == JFileChooser.CANCEL_OPTION) {

				      }
			      }
			      if (rVal == JFileChooser.CANCEL_OPTION) {

			      }
			}
		});
		button_1.setBounds(126, 142, 107, 23);
		panel_3.add(button_1);
		
		JPanel panel_4 = new JPanel();
		panel_4.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null)); //$NON-NLS-1$
		panel_4.setBounds(762, 584, 282, 147);
		contentPane.add(panel_4);
		panel_4.setLayout(null);
		
		JLabel lblOperacionesConNmeros = new JLabel(languageBundle.getString("AplicacionFTW.lblOperacionesConNmeros.text")); //$NON-NLS-1$
		lblOperacionesConNmeros.setBounds(89, 0, 173, 14);
		panel_4.add(lblOperacionesConNmeros);
		
		cbxOperarNumero = new JComboBox();
		cbxOperarNumero.setModel(new DefaultComboBoxModel(new String[] {"Sumar", "Restar", "Multiplicar", "Dividir"}));
		cbxOperarNumero.setBounds(53, 47, 165, 20);
		panel_4.add(cbxOperarNumero);
		
		JButton cmdAplicarOperacionNumero = new JButton(languageBundle.getString("AplicacionFTW.cmdAplicarOperacionNumero.text")); //$NON-NLS-1$
		cmdAplicarOperacionNumero.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				if(adnTrabajo == null)return;
				
				lblStatus.setText("Aplicando");
		    	lblStatus.update(lblStatus.getGraphics());
				
				float operando2 = Float.parseFloat(txtOperarNumero.getText());
				switch(cbxOperarNumero.getSelectedIndex()){
					case 0:
						adnTrabajo.opera(HiloExp.SUMA_NUMERO, operando2);
						break;
					case 1:
						adnTrabajo.opera(HiloExp.RESTA_NUMERO, operando2);
						break;
					case 2:
						adnTrabajo.opera(HiloExp.MULTIPLICA_NUMERO, operando2);
						break;
					case 3:
						adnTrabajo.opera(HiloExp.DIVIDE_NUMERO, operando2);
						break;
				}
				pintarCromosoma(adnTrabajo.getCromosomas()[cbxCromosoma.getSelectedIndex()]);
				lblStatus.setText("Listo");
		    	lblStatus.update(lblStatus.getGraphics());
			}
		});
		cmdAplicarOperacionNumero.setBounds(183, 113, 89, 23);
		panel_4.add(cmdAplicarOperacionNumero);
		
		txtOperarNumero = new JTextField();
		txtOperarNumero.setText(languageBundle.getString("AplicacionFTW.txtOperarNumero.text")); //$NON-NLS-1$
		txtOperarNumero.setBounds(53, 82, 165, 20);
		panel_4.add(txtOperarNumero);
		txtOperarNumero.setColumns(10);
		
		JLabel lblOperacinARealizar_1 = new JLabel(languageBundle.getString("AplicacionFTW.lblOperacinARealizar_1.text")); //$NON-NLS-1$
		lblOperacinARealizar_1.setBounds(10, 25, 172, 14);
		panel_4.add(lblOperacinARealizar_1);
		
		JLabel lblValor = new JLabel(languageBundle.getString("AplicacionFTW.lblValor.text")); //$NON-NLS-1$
		lblValor.setBounds(10, 69, 46, 14);
		panel_4.add(lblValor);
	}
	
	
	
	class OpenL implements ActionListener {
				
	    public void actionPerformed(ActionEvent e) {
	      JFileChooser c = new JFileChooser();
	      c.setFileFilter(new WigFileFilter());
	      // Demonstrate "Open" dialog:
	      int rVal = c.showOpenDialog(AplicacionFTW.this);
	      if (rVal == JFileChooser.APPROVE_OPTION) {
	        //dir.setText(c.getCurrentDirectory().toString());
	        
	    	lblStatus.setText("Cargando fichero " + c.getSelectedFile().toString());
	    	lblStatus.update(lblStatus.getGraphics());
	    	adnTrabajo = new DNA_Schizosaccharomyces_pombe(c.getSelectedFile().toString());

	    	cbxCromosoma.removeAllItems();
	        for(int i = 0; i < adnTrabajo.getCromosomas().length; i++){
	        	cbxCromosoma.addItem(adnTrabajo.getCromosomas()[i].getNombre());
	        }
	        
	        cbxCromosoma.setSelectedIndex(0);
	        //pintarCromosoma(adnTrabajo.getCromosomas()[0]);
	        
	        lblStatus.setText("Listo");
	    	lblStatus.update(lblStatus.getGraphics());
	      }
	      if (rVal == JFileChooser.CANCEL_OPTION) {

	      }
	    }
	  }

	  class SaveL implements ActionListener {
	    public void actionPerformed(ActionEvent e) {
	      JFileChooser c = new JFileChooser();
	      c.setFileFilter(new WigFileFilter());
	      // Demonstrate "Save" dialog:
	      int rVal = c.showSaveDialog(AplicacionFTW.this);
	      if (rVal == JFileChooser.APPROVE_OPTION) {
	    	  lblStatus.setText("Guardando fichero " + c.getSelectedFile().toString());
	    	  lblStatus.update(lblStatus.getGraphics());
	    	  adnTrabajo.printFile(c.getSelectedFile().toString());
	    	  lblStatus.setText("Listo");
	    	  lblStatus.update(lblStatus.getGraphics());
	      }
	      if (rVal == JFileChooser.CANCEL_OPTION) {
	    	  txtFicheroOperaciones.setText("You pressed cancel");
	        //dir.setText("");
	      }
	    }
	  }
	  
	  
	  class MuestraDialogo implements ActionListener {
		    public void actionPerformed(ActionEvent e) {
		    	JOptionPane.showMessageDialog(null, "FTW Finding Transcriptome with Wavelets\nAutor: Enrique Vázquez de Luis"/*activeBundle.getString("MSG_ACERCA_DE")*/, "", JOptionPane.INFORMATION_MESSAGE, null/*new ImageIcon(Menu.class.getClassLoader().getResource("res/Twisen.jpg"))*/);
		    }
		  }
}
